home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / pack / xpkdisk / xdname.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  92 lines

  1. /*-
  2.  * XDNAME.C
  3.  *
  4.  * Give info about the file names used for tracks.
  5.  *
  6.  * $Id: xdname.c,v 1.2 1993/11/08 13:18:19 Rhialto Rel $
  7.  * $Log: xdname.c,v $
  8.  * Revision 1.2  1993/11/08  13:18:19  Rhialto
  9.  * Add RCS tags.
  10.  *
  11.  *
  12.  * This code is (C) Copyright 1993 by Olaf Seibert. All rights reserved.
  13.  * May not be used or copied without a licence.
  14. -*/
  15. #include "xpkdisk.h"
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20.  
  21. static const char      OldFile[]= "Track%03x";
  22.  
  23. #define HASHTABLESIZE    72    /* Must be less than 13*13 */
  24.  
  25. void
  26. OldName(char *filename, int track)
  27. {
  28.     sprintf(filename, OldFile, track);
  29. }
  30.  
  31. int
  32. main(int argc, char **argv)
  33. {
  34.     char        oldname[64];
  35.     char        newname[64];
  36.     int         new2old = 0;
  37.     int         number = 0;
  38.     int         maxtrack;
  39.     int         hash;
  40.     int         i;
  41.  
  42.     if (argc < 2) {
  43.     usage:
  44.     printf("Usage: XDName [-r] [-n] <track>\n");
  45.     exit(10);
  46.     }
  47.  
  48.     while (argv[1][0] == '-') {
  49.     switch (argv[1][1]) {
  50.     case 'r':
  51.         new2old = 1;
  52.         break;
  53.     case 'n':
  54.         number = 1;
  55.         break;
  56.     default:
  57.         goto usage;
  58.     }
  59.     argv++;
  60.     argc--;
  61.     }
  62.     maxtrack = strtol(argv[1], NULL, 0);
  63.  
  64.     if (number) {
  65.     NewName(newname, maxtrack);
  66.     hash = Hash(strrchr(newname, '/') + 1) % HASHTABLESIZE;
  67.     printf("Track %d is %s ; hash = %d\n", maxtrack, newname, hash);
  68.  
  69.     return 0;
  70.     }
  71.  
  72.     printf("failat 31\n");
  73.     for (i = 0; i <= maxtrack; i++) {
  74.     if (!new2old && i % HASHTABLESIZE == 0) {
  75.         NewName(newname, i);
  76.         *strrchr(newname, '/') = '\0';
  77.         hash = Hash(newname) % HASHTABLESIZE;
  78.         printf("makedir %s ; hash = %d\n", newname, hash);
  79.     }
  80.     OldName(oldname, i);
  81.     NewName(newname, i);
  82.     if (new2old) {
  83.         hash = Hash(oldname) % HASHTABLESIZE;
  84.         printf("rename %s to %s ; hash = %d\n", newname, oldname, hash);
  85.     } else {
  86.         hash = Hash(strrchr(newname, '/') + 1) % HASHTABLESIZE;
  87.         printf("rename %s to %s ; hash = %d\n", oldname, newname, hash);
  88.     }
  89.     }
  90.     return 0;
  91. }
  92.